package com.javasea.spring.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 监听方式2，通过注解进行监听
 * 效果同 ReconnectApplicationListener
 */
@Slf4j
@Component
public class ReconnectApplicationListener2 {

    @Async("reconnectPool")
    @EventListener(ReconnectApplicationEvent.class)
    public void listener(ReconnectApplicationEvent event) throws InterruptedException {
        log.info("收到重连事件，开始重连：[{}]", event.getMessage());
        Thread.sleep(5000);
        log.info("收到重连事件，重连完成");
    }

}
